package taskit.datastructures;

import taskit.logic.ParserReturnObject;
import taskit.storage.Data;
import taskit.test.Log;

//@author A0087072A
public class CommandComplete extends Command {
	public CommandComplete(Task task, Data internalData) {
		this.task = task;
		data = internalData;
	}

	/*
	 * TODO: create new test result
	 * @see Command#execute(boolean)
	 */
	@Override
	public void execute(boolean test) throws Exception {
		Log.add("CommandComplete.java: execute()");
		if (task instanceof Deadline) {
			Deadline deadline = (Deadline) task;
			deadline.toggleComplete();
			if (test) {
				testResult = 0;
			}
		} else if (task instanceof Floating) {
			Floating floating = (Floating) task;
			floating.toggleComplete();
			data.delete(floating);
			data.addToArchive(floating);
			ParserReturnObject.setAction(ParserReturnObject.ACTION_UPDATE_FT);
			if (test) {
				testResult = 0;
			}
		}
	}
	
	@Override
	public Command reverse() {
		return new CommandUncomplete(task, data);
	}
}
